package com.heima.test4j;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

/** 识别图片中的文字
 * @author ZQH
 * @version 1.0
 * @date 2023/8/13 16:52
 */
public class Application {
    public static void main(String[] args) throws TesseractException {
        //创建实例
        ITesseract tesseract = new Tesseract();
        //设置字体库路径
        String path = Application.class.getResource("/").getPath();
        tesseract.setDatapath("F:\\tessdata");
        //设置语言  简体中文
        tesseract.setLanguage("chi_sim");
        //识别图片
        File file = new File("C:\\Users\\zhangqihang\\Pictures\\Saved Pictures\\image-20210524161243572.png");
        String s = tesseract.doOCR(file);
        System.out.println(s.replaceAll("\\r|\\n",""));

    }
}
